package com.ts.utils;

import java.io.InputStream;
import java.util.Properties;

public class PropertyUtils {
	//1.url、文件路径 存放文件
	private static final String config = "/application-dev.properties";
	
	/**
	 * 读取指定properties文件
	 * @param propertyname
	 * @return value
	 * @author cyj
	 */
	public  String readProp(String filename,String propertyname) throws Exception{
		String url = filename;
		Properties prop = new Properties();
		String value = "";
		try {
			InputStream m=this.getClass().getResourceAsStream(url);
			prop.load(m);
			value=prop.getProperty(propertyname);
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception("读取config.properties文件出现错误！",e);
		}
		return value;
	}
	/**
	 * 1.从config.properties文件中获取变量值
	 * @param propertyname
	 * @return value
	 * @author zbb
	 */
	public static String getProp(String propertyname) throws Exception{
		String value="";
		try {
			value=new PropertyUtils().readProp(config,propertyname);
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception("读取config.properties文件出现错误！",e);
		}
		return value;
	}
	
	
	/**
	 * 2.从config.properties文件中获取变量值
	 * @param propertyname
	 * @return value
	 * @author zbb
	 */
	public static String getVarValue(String propertyname) throws Exception{
		String value="";
		try {
			value=new PropertyUtils().readProp(config,propertyname);
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception("读取config.properties文件出现错误！",e);
		}
		return value;
	}
	
	
	
	
	
	
	//测试
	public static void main(String[] args){
		try{
//			System.out.println(getVarValue("rylb_index")+"========++++====");

			String aaa = getProp("spring.http.multipart.location");
			System.out.println(aaa);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	
		
	
}
